/**************************************************************************
 *         Copyright(c) 2007 by Sunplus mMedia  Technology Co., Ltd.       *
 *                                                                         *
 *  This software is copyrighted by and is the property of Sunplus mMedia  *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno- *
 *  logy Co., Ltd. This software may only be used in accordance with the   *
 *  corresponding license agreement. Any unauthorized use, duplication,    *
 *  distribution, or disclosure of this software is expressly forbidden.   *
 *                                                                         *
 *  This Copyright notice "M U S T" not be removed or modified without     *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.          *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this  *
 *  software without notice.                                               *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd.                                    *
 *  19-1, Innovation First Road, Science-Based Industrial Park,            *
 *  Hsin-Chu, Taiwan, R.O.C.                                               *
 *                                                                         *
 **************************************************************************/
#ifndef __SP1K_AAA_API_H__
#define __SP1K_AAA_API_H__

/** \file sp1k_aaa_api.h
 * @brief		Spca1528 3A related interface which include: a)Initial setting, b) Parameter setting, C) Mode setting, d) Status getting of AE/AWB.
 */

#include "aaa_api.h"
#include "sp1k_def.h"

/**************************************************************************
 *                           C O N S T A N T S                            *
 **************************************************************************/
#define SP1K_AAA_AE_CNT_RANGE 256
#define SP1K_AAA_AWB_CNT_RANGE 256

enum {
	SP1K_AE_TARGET_LUMA = 0,/*< AE target Luma value, defult is 120.*/
	SP1K_AE_EV_COMP,/*< Target Luma value, defult is 120.*/
	SP1K_AE_FRAME_RATE,/*< Target Luma value, defult is 120.*/
	SP1K_AE_METERING,/*< Target Luma value, defult is 120.*/
	SP1K_AE_USING_AWB_GAIN,/*< using AWB GAIN for increasing dynamic range*/
	SP1K_AE_CONVERAGE_ZONE,/*< Target Luma value, defult is 120.*/
	SP1K_AE_GAINSHUTTERTBL,/*< Target Luma value, defult is 120.*/
	SP1K_AW_H_WINDOW_SIZE,/*< Target Luma value, defult is 120.*/
	SP1K_AW_V_WINDOW_SIZE,/*< Target Luma value, defult is 120.*/
	SP1K_AE_LowLight,/*< The status of AE which means light too low.*/
	SP1K_AE_IsReady,/*< The status of AE which means AE is finished or not, 0 is not ready and 1 is ready.*/
	SP1K_AE_EV_GET,/*< Get the current EV step */
	SP1K_AE_Count/*< The index of AE which means how many time does AE have been calculate.*/
};

// Here are AWB parameter setting function
// To set parameter: sp1kAwbScaleSet( id, value );
enum {
	SP1K_AWB_IsReady = 0,/*< The status of AWB which means AWB is finished or not, 0 is not ready and 1 is ready.*/
	SP1K_AWB_Jump_Scale,/*< The movement of AWB gain value, normal range is from 1~50. The higher the value is, the fast it change.*/  //Jim@0527 - AWB Scale Adjust
	SP1K_AWB_Count,/*< The index of AWB which means how many time does AWB have been calculate.*/
	SP1K_AWB_PARAM_CWB_FID,
	SP1K_AWB_PARAM_WAIT_READY_MIN_TIME, // the min AE/AWB waiting time
	SP1K_AWB_PARAM_CUSTOM_R_GAIN_SHIFT, // the custom R gain shift
	SP1K_AWB_PARAM_CUSTOM_B_GAIN_SHIFT, // the custom B gain shif
	SP1K_AWB_PARAM_MAX
};

enum{
	SP1K_FRAME_RATE_30   = 0,
	SP1K_FRAME_RATE_25   = 1,
	SP1K_FRAME_RATE_15   = 2,
	SP1K_FRAME_RATE_12P5 = 3,
	SP1K_FRAME_RATE_TOT,
};

enum{
	SP1K_FLICKER_60 = 60,/*< The selector of flicker under 60Hz light source.*/
	SP1K_FLICKER_50 = 50,/*< The selector of flicker under 50Hz light source.*/
};

enum{
	SP1K_AE_METER_MULTI=0,/*< AE detect window which have the widest range within the view.*/
	SP1K_AE_METER_CENTER,/*< AE detect window which have the normal range at the center of view.*/
	SP1K_AE_METER_SPOT/*< AE detect window which only have a narrow range at the center of view.*/
};

enum{
	SP1K_AE_EXP_COMP_M20 = 0,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M19,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M18,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M17,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M16,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M15,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M14,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M13,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M12,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M11,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M10,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M09,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M08,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M07,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M06,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M05,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M04,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M03,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M02,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_M01,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_00,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P01,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P02,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P03,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P04,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P05,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P06,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P07,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P08,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P09,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P10,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P11,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P12,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P13,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P14,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P15,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P16,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P17,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P18,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P19,/*< Target Luma value, defult is 120.*/
	SP1K_AE_EXP_COMP_P20/*< Target Luma value, defult is 120.*/
};

enum{
	SP1K_AWB_MODE_DISABLE = 0,/*< One mode of WB which means WB is Disabled.*/
	SP1K_AWB_MODE_AUTO,/*< One mode of WB which include all CTC curve.*/
	SP1K_AWB_MODE_TUNGSTENG,/*< One mode of WB which set the range only near "TUNGSTENG".*/
	SP1K_AWB_MODE_FLUORESCENT,/*< One mode of WB which set the range only near "FLUORESCENT".*/
	SP1K_AWB_MODE_DAYLIGHT,/*< One mode of WB which set the range only near "DAYLIGHT".*/
	SP1K_AWB_MODE_CLOUDY,/*< One mode of WB which set the range only near "CLOUDY".*/
	SP1K_AWB_MODE_CUSTOM,/*< One mode of WB which will let user set rb gain.*/
	SP1K_AWB_MODE_UNITY,/*< One mode of WB which means WB is Disabled.*/
	SP1K_AWB_MODE_CONTINUE/*< One mode of WB which means WB will not change and keep the last value.*/
};

#define SP1K_AWB_SPEED_FAST_ONCE 255

/**************************************************************************
 *                              M A C R O S                               *
 **************************************************************************/
#ifdef SP1K_DOXY_GEN
/**
 * @fn void sp1kAeModeSet(UINT8 mode)
 * @brief	To turn ON/OFF AE function.
 * @param[in] mode	 The status of AE:
 *\n                              0: AE turn OFF.
 *\n                              1: AE turn ON.
 * @retval none
 */
void sp1kAeModeSet(UINT8 mode);

/**
 * @fn void sp1kAwbModeSet(UINT8 mode)
 * @brief	To select mode of AWB function.
 * @param[in] mode	 The mode of AWB:
 *\n                              SP1K_AWB_MODE_DISABLE for AWB disable.
 *\n                              SP1K_AWB_MODE_AUTO for AWB AUTO mode.
 *\n                              SP1K_AWB_MODE_TUNGSTENG for TUNGSTENG mode.
 *\n                              SP1K_AWB_MODE_FLUORESCENT for FLUORESCENT mode.
 *\n                              SP1K_AWB_MODE_DAYLIGHT for DAYLIGHT mode.
 *\n                              SP1K_AWB_MODE_CLOUDY for CLOUDY mode.
 *\n                              SP1K_AWB_MODE_CONTINUE for keep last setting.
 * @retval none
 */
void sp1kAwbModeSet(UINT8 mode);

#else
#define sp1kAeModeSet AAA_AEModeEnable
#define sp1kAwbModeSet AAA_AWBModeEnable
#endif

/**************************************************************************
 *                          D A T A    T Y P E S                          *
 **************************************************************************/

/**************************************************************************
 *                         G L O B A L    D A T A                         *
 **************************************************************************/

/**************************************************************************
 *                 E X T E R N A L    R E F E R E N C E S                 *
 **************************************************************************/

/**************************************************************************
 *               F U N C T I O N    D E C L A R A T I O N S               *
 **************************************************************************/
/**
 * @fn UINT8 sp1kAeAwbInit(void)
 * @brief	Initial AE/AWB setting.  The function must be called before the system switch to peview mode
 * @retval none
 */
UINT8 sp1kAeAwbInit(void);

/**
 * @fn void sp1kAeParamSet(UINT8 selector, UINT16 val)
 * @brief	Entering parameter for AE setting
 * @param[in] selector	 To set the parameter of AE:
 *\n                              SP1K_AE_TARGET_LUMA
 *\n                              SP1K_AE_EV_COMP:
 *\n                              SP1K_AE_FRAME_RATE
 *\n                              SP1K_AE_METERING
 * @param[in] val	 Value of each setting above.
 *\n                              0~255 for selector SP1K_AE_TARGET_LUMA.
 *\n                              SP1K_AE_EXP_COMP_M20 ~ SP1K_AE_EXP_COMP_00 ~ SP1K_AE_EXP_COMP_P20 for selector SP1K_AE_EV_COMP.
 *\n                              SP1K_FRAME_RATE_30, SP1K_FRAME_RATE_25, SP1K_FRAME_RATE_15, SP1K_FRAME_RATE_12P5 for selector SP1K_AE_FRAME_RATE.
 *\n                              SP1K_AE_METER_MULTI, SP1K_AE_METER_CENTER, SP1K_AE_METER_SPOT for selector SP1K_AE_TARGET_LUMA.
 * @retval none
 */
void sp1kAeParamSet(UINT8 selector, UINT16 val);

/**
 * @fn void sp1kAwbScaleSet(UINT8 selector, UINT8 val)
 * @brief	Entering the step of AWB gain jump.
 * @param[in] selector	 To set the jump step of AWB gain:
 *\n                              SP1K_AWB_Jump_Scale.
 * @param[in] val	 Jump step value (The higher the value is, the fast it change):
 *\n                              When at preview, the recommand value is 8 or lower to minmize the visible color change.
 *\n                              When at capture and AWB is not ready, the recommand value is 40 or higher to reduce the shutter lag.
 * @retval none
 */
void sp1kAwbScaleSet(UINT8 selector, UINT8 val);		//Jim@0527 - AWB Scale Adjust

/**
 * @fn UINT8 sp1kAeStatusGet(UINT8 selector, UINT8* val)
 * @brief	To get the calculate status of AE.
 * @param[in] selector	 AE status:
 *\n                              SP1K_AE_IsReady - Means AE ready or not.
 *\n                              SP1K_AE_LowLight - Means AE lowlight or not.
 *\n                              SP1K_AE_Count - The time that AE have been calculate.
 * @param[out] val	 AE status value:
 *\n                              0: Not ready, 1: Ready for selector SP1K_AE_IsReady.
 *\n                              0: Normal light, 1: Low light for selector SP1K_AE_LowLight.
 *\n                              0~255 for selector SP1K_AE_Count.
 * @retval error code -  SUCCESS: 0, FAIL: 1
 */
UINT8 sp1kAeStatusGet(UINT8 selector, UINT8* val);

/**
 * @fn UINT8 sp1kAwbStatusGet(UINT8 selector, UINT8* val)
 * @brief	To get the calculate status of AWB.
 * @param[in] selector	 AWB status:
 *\n                              SP1K_AWB_IsReady - Means AWB ready or not.
 *\n                              SP1K_AWB_Count - The calculate time of AWB.
 * @param[out] val	 AWB status value:
 *\n                              0: Not ready, 1: Ready for selector SP1K_AWB_IsReady.
 *\n                              0~255 for selector SP1K_AWB_Count.
 * @retval error code -  SUCCESS: 0, FAIL: 1
 */
UINT8 sp1kAwbStatusGet(UINT8 selector, UINT8* val);

void sp1kAwbParaInit( UINT8 fileId );
UINT8 sp1kAAAReadyGet( UINT8 mode, UINT8 start );
UINT8 sp1kCwbSnap( void );

/* compile backward compatible. */
#define sp1kAEModeSet    sp1kAeModeSet
#define sp1kAWBModeSet   sp1kAwbModeSet
#define sp1kAEAWBInit    sp1kAeAwbInit
#define sp1kAEParamSet   sp1kAeParamSet
#define sp1KAWBScaleSet  sp1kAwbScaleSet
#define sp1KAEStatusGet  sp1kAeStatusGet
#define sp1KAWBStatusGet sp1kAwbStatusGet

#endif //__SP1K_AAA_API_H__

